// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html



cc.Class({
    extends: cc.Component,

    properties: {
        //骰子节点
        gamePoints:cc.Node,
        game1:cc.Sprite,
        game2:cc.Sprite,
        game3:cc.Sprite,
       //骰子总数节点
        gameNumTotal:cc.Node,
        gameNumTotalLebel:cc.Label,
        //输赢节点
        win:cc.Node,
        winLable:cc.Label,
        lose:cc.Node,

        win2Ya:cc.Node,
        bigWinLab:cc.Label,
        bigBetLab:cc.Label,
        smallWinLab:cc.Label,
        smallBetLab:cc.Label,
        
        spriteFrame: {
            default: [],
            type: cc.spriteFrame
        },
        spriteBallFrame: {
            default: [],
            type: cc.spriteFrame
        },
        
    },

    // start() {
    //     // 动态创建并添加节点
    //    // let newNode = new cc.Node();
    //    // this.node.addChild(newNode);
 
    //     // 设置新节点的位置（假设你的节点是在编辑器中定义好的）
    //     newNode.setPosition(cc.v2(100, 100));
 
    //     // 动态加载Sprite Frame（如果需要）
    //     // let spriteFrame = cc.resources.load('path_to_your_sprite_frame', cc.SpriteFrame);
    //     // spriteFrame.then((frame) => {
    //     //     let sprite = newNode.addComponent(cc.Sprite);
    //     //     sprite.spriteFrame = frame;
    //     // });
 
    //     // 添加左移动画
    //     let moveToAction = cc.moveTo(2, cc.v2(-0, 100)); // 2秒移动到屏幕左侧100点的位置
    //     this.gameNumTotal.runAction(moveToAction);
    // },
    
    onLoad(){
        
      
        cc.resources.load("atlas/game", cc.SpriteAtlas, (err, atlas) => {
            this.spriteFrame[0] = atlas.getSpriteFrame('game1');
            this.spriteFrame[1] = atlas.getSpriteFrame('game2');
            this.spriteFrame[2] = atlas.getSpriteFrame('game3');
            this.spriteFrame[3] = atlas.getSpriteFrame('game4');
            this.spriteFrame[4] = atlas.getSpriteFrame('game5');
            this.spriteFrame[5] = atlas.getSpriteFrame('game6');
        })
        cc.resources.load("atlas/game2", cc.SpriteAtlas, (err, atlas) => {
            this.spriteBallFrame[0] = atlas.getSpriteFrame('icon_blue');
            this.spriteBallFrame[1] = atlas.getSpriteFrame('icon_blue');
            this.spriteBallFrame[2] = atlas.getSpriteFrame('icon_red');
            
        })

       

    },
    gameResult:function(sprite,gameNum){

        for (var i=0;i<6;i++){ 
         if (gameNum-1==i) {
            sprite.spriteFrame= this.spriteFrame[i];}
        }
    },
    gameOpenJiang:function(points){

        this.total= points[0]+points[1]+points[2];
        this.gameResult(this.game1,points[0]);
        this.gameResult(this.game2,points[1]);
        this.gameResult(this.game3,points[2]);
        this.showGameNumTotal(true);
        this.show(true);
        var sprite = this.gameNumTotal.getComponent(cc.Sprite)
        if (this.total>10) {
            
            sprite.spriteFrame= this.spriteBallFrame[1] ; 
        }else{
            sprite.spriteFrame= this.spriteBallFrame[2] ; 
        }

       
     
    },

   show:function(show){
    this.gamePoints.active=show;  
   },
   showGameNumTotal:function(show){
    this.gameNumTotal.active=show;
    // if (show) {
    //     let moveToAction = cc.moveTo(2, cc.v2(0, 0)); // 2秒移动到屏幕左侧100点的位置
    //     this.gameNumTotal.runAction(moveToAction);
    // }else{
    //     this.gameNumTotal.setPosition(cc.v2(100, 100));
    // }
   
   
    this.gameNumTotalLebel.string=this.total;
   },

   showWin:function(winScore){
    this.win.active=true;
    this.winLable.string ='+'+winScore;
    
   },
   showLose:function(){
    this.lose.active=true;
   },

   showWin2Ya:function(bigWin,smallWin,bigBet,smallBet){
    this.win2Ya.active=true;
    this.bigBetLab.string =bigBet;
    this.smallBetLab.string =smallBet;
    this.bigWinLab.string =bigWin;
    this.smallWinLab.string =smallWin;
    
    
   },

   hide(){
    this.win.active=false;
    this.lose.active=false;
    this.gamePoints.active=false; 
    this.showGameNumTotal(false);
    this.win2Ya.active=false;
   },



   

    


    // update (dt) {},
});
